package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**用户业务层实现
 * @Description:
 * @Version: V1.0
 */

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean save(User user) {
        return userMapper.save(user);
    }


    @Override
    public boolean update(User user) {
        return userMapper.update(user);
    }


    @Override
    public boolean delete(Integer id) {
        return userMapper.delete(id);
    }


    @Override
    public PageInfo<User> findAll(Integer page, Integer size) {

        PageHelper.startPage(page,size);
        List<User> all = userMapper.findAll();
        PageInfo<User> pageInfo=new PageInfo<>(all);
        return pageInfo;
    }

    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }


    @Override
    public User login(String username, String password) {
        User byUsernameAndPwd = userMapper.findByUsernameAndPwd(username, password);
        int i=1/0;
        System.out.println(byUsernameAndPwd);
        return byUsernameAndPwd;
    }

    @Override
    public PageInfo<User> getUsers(Integer page, Integer size,User user) {
        PageHelper.startPage(page,size);
        List<User> all = userMapper.getUsers(user);
        PageInfo<User> pageInfo=new PageInfo<>(all);
        return pageInfo;
    }

}
